﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.IO;


namespace  PI_CS_Library
{
    public static class Serial
    {
        public static void SerializeObject(string fileName, Object pObject)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(pObject.GetType());
                TextWriter textWriter = new StreamWriter(@fileName);
                serializer.Serialize(textWriter, pObject);
                textWriter.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);

            }
        }

        public static Dictionary<string, int> DeserializeDictionary(string _filename)
        {
            XmlReader reader = XmlReader.Create(_filename);
            DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, int>));

            Dictionary<string, int> result = (Dictionary<string, int>)serializer.ReadObject(reader);
            reader.Close();

            return result;
        }
    }   
}
